package lzyc.pointsManagement.business.attachment.convertor;

import lzyc.pointsManagement.business.attachment.dto.AttachmentsDto;
import lzyc.pointsManagement.business.attachment.domain.Attachments;
import lzyc.pointsManagement.common.utils.StringUtils;
import lzyc.pointsManagement.common.utils.uuid.IdUtils;

import java.util.Date;

public class AttachmentsConvertor {
    public static AttachmentsDto convertToDto(Attachments entity)
    {
        AttachmentsDto dto = new AttachmentsDto();
        dto.setType(entity.getType());
        dto.setCreateTime(entity.getCreateTime());
        dto.setId(entity.getId());
        dto.setName(entity.getName());
        dto.setPath(entity.getPath());
        dto.setSize(entity.getSize());
        dto.setBizId(entity.getBizId());
        return dto;
    }
    public static Attachments convertToEntity(AttachmentsDto dto)
    {
        Attachments entity = new Attachments();
        if (dto != null) {
            if (StringUtils.isEmpty(dto.getId())) {
                entity.setId(IdUtils.randomUUID());
                dto.setId(entity.getId());
            } else {
                entity.setId(dto.getId());
            }
            entity.setType(dto.getType());
            if (dto.getCreateTime() == null) {
                entity.setCreateTime(new Date());
                dto.setCreateTime(entity.getCreateTime());
            } else {
                entity.setCreateTime(dto.getCreateTime());
            }
            entity.setName(dto.getName());
            entity.setPath(dto.getPath());
            entity.setSize(dto.getSize());
            entity.setBizId(dto.getBizId());
        }
        return entity;
    }
}
